//package com.fecean.aabbc.netty.server.prod5;
//
//import com.fecean.aabbc.netty.message6.MessageBuilder;
//import com.fecean.aabbc.netty.dispatcher.ResponseFuture;
//import com.fecean.aabbc.netty.message6.ResponseMessage;
//import com.fecean.aabbc.netty.server.prod6.NettyClientPool;
//import com.fecean.aabbc.netty.server.prod6.NettyClientWrapper;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.util.Optional;
//
///**
// * NettyClientSender
// *
// * @author: chenfenghai
// * @version: 1.0
// * @date: 2020-03-12 16:44
// * @blame Team
// */
//@Slf4j
//@Component
//public class NettyClientSender {
//
//    @Resource
//    NettyClientPool nettyClientPool;
//
//    /**
//     ** 发送通知
//     * @param tenantId 租户ID
//     * @param cinemaCode 影院编码
//     * @param content 消息内容
//     */
//    public void sendNotice(String tenantId, String cinemaCode, String content){
//        Optional<NettyClientWrapper> optionalChannel = nettyClientPool.getClientChannel(tenantId, cinemaCode);
//        optionalChannel.ifPresent(client -> {
//            MessageBuilder builder = MessageBuilder.buildNoticeMessage(tenantId, cinemaCode, content);
//            client.getContext().writeAndFlush(builder.getMessage());
//            log.info("客户端[{}-{}]发送通知：{}",
//                    builder.getNoticeMessage().getTenantId(),
//                    builder.getNoticeMessage().getCinemaCode(),
//                    builder.getNoticeMessage());
//        });
//    }
//
//    /**
//     ** 发送请求
//     * @param tenantId 租户ID
//     * @param cinemaCode 影院编码
//     * @param content 消息内容
//     */
//    public ResponseMessage sendRequest(String tenantId, String cinemaCode, String content){
//        Optional<NettyClientWrapper> optionalChannel = nettyClientPool.getClientChannel(tenantId, cinemaCode);
//        if(optionalChannel.isPresent()){
//            MessageBuilder builder = MessageBuilder.buildRequestMessage(tenantId, cinemaCode, content);
//            ResponseFuture future = new ResponseFuture(optionalChannel.get().getContext().channel(), builder.getMessage());
//            optionalChannel.get().getContext().writeAndFlush(builder.getMessage());
//            log.info("客户端[{}-{}]发送请求：{}",
//                    builder.getRequestMessage().getTenantId(),
//                    builder.getRequestMessage().getCinemaCode(),
//                    builder.getRequestMessage());
//            // 等待获取响应结果
//            return future.get();
//        }
//        return null;
//    }
//}
